<!DOCTYPE html>












  


<html class="theme-next pisces use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">












<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />






















<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=6.3.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=6.3.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=6.3.0">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=6.3.0" color="#222">









<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '6.3.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta property="og:type" content="website">
<meta property="og:title" content="我的云笔记">
<meta property="og:url" content="http://yoursite.com/page/2/index.html">
<meta property="og:site_name" content="我的云笔记">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="我的云笔记">






  <link rel="canonical" href="http://yoursite.com/page/2/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>我的云笔记</title>
  






  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?5102824f4157d2cbdb282a1a889d910e";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">我的云笔记</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
    
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>



<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
        
          
          <li class="menu-item menu-item-home">
    <a href="/blog/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-tags">
    <a href="/blog/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
  </li>
        
        
        
          
          <li class="menu-item menu-item-categories">
    <a href="/blog/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
  </li>

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
            

          
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/docker/docker-net/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/docker/docker-net/" itemprop="url">
                  docker网络设置
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-08-30 07:44:24" itemprop="dateCreated datePublished" datetime="2018-08-30T07:44:24+08:00">2018-08-30</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-02-04 11:22:37" itemprop="dateModified" datetime="2019-02-04T11:22:37+08:00">2019-02-04</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/docker/" itemprop="url" rel="index"><span itemprop="name">docker</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/docker/docker-net/" class="leancloud_visitors" data-flag-title="docker网络设置">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>个人笔记</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/docker/docker-net/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/kubernets/kubernets安装/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/kubernets/kubernets安装/" itemprop="url">
                  未命名
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-02-02 15:54:31" itemprop="dateCreated datePublished" datetime="2019-02-02T15:54:31+08:00">2019-02-02</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-02-03 21:36:35" itemprop="dateModified" datetime="2019-02-03T21:36:35+08:00">2019-02-03</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/kubernets/" itemprop="url" rel="index"><span itemprop="name">kubernets</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/kubernets/kubernets安装/" class="leancloud_visitors" data-flag-title="">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>准备工作</p>
<p>master01:192.168.1.110</p>
<p>node01:192.168.1.106</p>
<p>关闭防火墙</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl disable firewalld</span><br><span class="line">iptables -F</span><br></pre></td></tr></table></figure>
<p>yum安装</p>
<p>master</p>
<p>192.168.1.110</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install kubernetes-master etcd -y</span><br></pre></td></tr></table></figure>
<p>配置</p>
<p>vim /etc/etcd/etcd.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ETCD_DATA_DIR=&quot;/var/lib/etcd/abc&quot;</span><br><span class="line">ETCD_LISTEN_PEER_URLS=&quot;http://192.168.1.110:2380&quot;</span><br><span class="line">ETCD_LISTEN_CLIENT_URLS=&quot;http://192.168.1.110:2379&quot;</span><br><span class="line">ETCD_NAME=&quot;etcd1&quot;</span><br><span class="line">ETCD_INITIAL_ADVERTISE_PEER_URLS=&quot;http://192.168.1.110:2380&quot;</span><br><span class="line">ETCD_ADVERTISE_CLIENT_URLS=&quot;http://192.168.1.110:2379&quot;</span><br><span class="line">ETCD_INITIAL_CLUSTER=&quot;etcd1=http://192.168.1.110:2380,etcd2=http://192.168.1.106:2380&quot;</span><br></pre></td></tr></table></figure>
<p>vim  /etc/kubernetes/apiserver</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">KUBE_API_ADDRESS=&quot;--insecure-bind-address=127.0.0.1&quot;</span><br><span class="line">KUBE_ETCD_SERVERS=&quot;--etcd-servers=http://192.168.1.110:2379,http://192.168.1.106:2379&quot;</span><br><span class="line">KUBE_SERVICE_ADDRESSES=&quot;--service-cluster-ip-range=10.254.0.0/16&quot;</span><br><span class="line">KUBE_API_ARGS=&quot;&quot;</span><br></pre></td></tr></table></figure>
<p>vim /etc/kubernetes/config</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">KUBE_LOGTOSTDERR=&quot;--logtostderr=true&quot;</span><br><span class="line">KUBE_LOG_LEVEL=&quot;--v=0&quot;</span><br><span class="line">KUBE_ALLOW_PRIV=&quot;--allow-privileged=false&quot;</span><br><span class="line">KUBE_MASTER=&quot;--master=http://192.168.1.110:8080&quot;</span><br></pre></td></tr></table></figure>
<p>重启</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>停止</span><br><span class="line">systemctl stop etcd</span><br><span class="line">systemctl stop kube-apiserver</span><br><span class="line">systemctl stop kube-controller-manager</span><br><span class="line">systemctl stop kube-scheduler</span><br><span class="line"><span class="meta">#</span>启动</span><br><span class="line">systemctl daemon-reload</span><br><span class="line">systemctl restart etcd</span><br><span class="line">systemctl restart kube-apiserver</span><br><span class="line">systemctl restart kube-controller-manager</span><br><span class="line">systemctl restart kube-scheduler</span><br></pre></td></tr></table></figure>
<p>查看</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kubectl get nodes --insecure-skip-tls-verify=true</span><br></pre></td></tr></table></figure>
<p>node</p>
<p>192.168.1.105</p>
<p>安装</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install kubernetes-node etcd flannel -y</span><br></pre></td></tr></table></figure>
<p>配置</p>
<p>vim /etc/etcd/etcd.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ETCD_DATA_DIR=&quot;/var/lib/etcd/default.etcd&quot;</span><br><span class="line">ETCD_LISTEN_PEER_URLS=&quot;http://192.168.1.106:2380&quot;</span><br><span class="line">ETCD_LISTEN_CLIENT_URLS=&quot;http://192.168.1.106:2379,http://127.0.0.1:2379&quot;</span><br><span class="line">ETCD_NAME=&quot;etcd2&quot;</span><br><span class="line">ETCD_INITIAL_ADVERTISE_PEER_URLS=&quot;http://192.168.1.106:2380&quot;</span><br><span class="line">ETCD_ADVERTISE_CLIENT_URLS=&quot;http://192.168.1.106:2379&quot;</span><br><span class="line">ETCD_INITIAL_CLUSTER=&quot;etcd1=http://192.168.1.110:2380,etcd2=http://192.168.1.106:2380&quot;</span><br></pre></td></tr></table></figure>
<p>vim /etc/kubernetes/kubelet</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">KUBELET_ADDRESS=&quot;--address=0.0.0.0&quot;</span><br><span class="line">KUBELET_HOSTNAME=&quot;--hostname-override=node01.kube.wang&quot;</span><br><span class="line">KUBELET_API_SERVER=&quot;--api-servers=http://192.168.1.110:8080&quot;</span><br><span class="line">KUBELET_POD_INFRA_CONTAINER=&quot;--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest&quot;</span><br><span class="line">KUBELET_ARGS=&quot;&quot;</span><br></pre></td></tr></table></figure>
<p>启动</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reload</span><br><span class="line">systemctl restart kube-proxy</span><br><span class="line">systemctl restart kubelet</span><br></pre></td></tr></table></figure>
<p>客户端设置kubectl</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">kubectl config set-cluster kubernetes --server=http://192.168.1.110:8080</span><br><span class="line">kubectl config set-context kubernetes --cluster=kubernetes</span><br><span class="line">kubectl config use-context kubernetes</span><br></pre></td></tr></table></figure>
<p>dashboard</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker pull docker.io/mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1</span><br><span class="line">docker tag docker.io/mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1  k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1</span><br></pre></td></tr></table></figure>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/kubernets/kubernets安装/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/uncategorized/kubenetes-ca/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/uncategorized/kubenetes-ca/" itemprop="url">
                  未命名
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-02-03 19:52:44 / 修改时间：20:48:50" itemprop="dateCreated datePublished" datetime="2019-02-03T19:52:44+08:00">2019-02-03</time>
            

            
              

              
            
          </span>

          

          
            
          

          
          
             <span id="/blog/uncategorized/kubenetes-ca/" class="leancloud_visitors" data-flag-title="">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p><a href="https://www.kubernetes.org.cn/3789.html" target="_blank" rel="noopener">https://www.kubernetes.org.cn/3789.html</a></p>
<p>安装生成工具</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">yum install wget</span><br><span class="line">wget https://pkg.cfssl.org/R1.2/cfssl_linux-amd64</span><br><span class="line">wget https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64</span><br><span class="line">chmod +x cfssl_linux-amd64 cfssljson_linux-amd64</span><br><span class="line">mv cfssl_linux-amd64 /usr/local/bin/cfssl</span><br><span class="line">mv cfssljson_linux-amd64 /usr/local/bin/cfssljson</span><br></pre></td></tr></table></figure>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/uncategorized/kubenetes-ca/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/uncategorized/fdisk/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/uncategorized/fdisk/" itemprop="url">
                  未命名
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-02-03 12:41:14 / 修改时间：13:49:59" itemprop="dateCreated datePublished" datetime="2019-02-03T12:41:14+08:00">2019-02-03</time>
            

            
              

              
            
          </span>

          

          
            
          

          
          
             <span id="/blog/uncategorized/fdisk/" class="leancloud_visitors" data-flag-title="">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>查看为分配的磁盘</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">fdisk -l</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1549168894081.png" alt="1549168894081"></p>
<p>/dev/sdb 在文件系统里没有,说明未初始化</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>开始分区</span><br><span class="line">fdisk /dev/sdb</span><br><span class="line"><span class="meta">#</span>依次输入</span><br><span class="line">n </span><br><span class="line">p</span><br><span class="line">1</span><br><span class="line">w</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1549169224094.png" alt="1549169224094"></p>
<p>查看新创建的磁盘</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ls /dev/sd*</span><br><span class="line"><span class="meta">#</span>多出2个/dev/sdb和/dev/sdb1</span><br></pre></td></tr></table></figure>
<p><img src="/blog/images/1549169438377.png" alt="1549169438377"></p>
<p>挂载</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span>格式化</span><br><span class="line">mkfs.ext4 /dev/sdb1 </span><br><span class="line"><span class="meta">#</span>创建目标目录</span><br><span class="line">mkdir /common</span><br><span class="line"><span class="meta">#</span>mount -t 表示文件系统</span><br><span class="line">mount -t ext4 /dev/sdb1 /common</span><br></pre></td></tr></table></figure>
<p>开机挂载</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/fstab  </span><br><span class="line">/dev/sdb1 /common ext4 errors=remount-ro 0 1</span><br></pre></td></tr></table></figure>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/uncategorized/fdisk/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/http/httpclient/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/http/httpclient/" itemprop="url">
                  未命名
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-01-07 19:19:14" itemprop="dateCreated datePublished" datetime="2019-01-07T19:19:14+08:00">2019-01-07</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-01-31 16:27:43" itemprop="dateModified" datetime="2019-01-31T16:27:43+08:00">2019-01-31</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/http/" itemprop="url" rel="index"><span itemprop="name">http</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/http/httpclient/" class="leancloud_visitors" data-flag-title="">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>httpclient使用</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://www.cnblogs.com/trust-freedom/p/6349502.html</span><br></pre></td></tr></table></figure>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/http/httpclient/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/redis/redis/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/redis/redis/" itemprop="url">
                  redis配置
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-01-26 13:50:08" itemprop="dateCreated datePublished" datetime="2019-01-26T13:50:08+08:00">2019-01-26</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-01-31 16:08:39" itemprop="dateModified" datetime="2019-01-31T16:08:39+08:00">2019-01-31</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/redis/" itemprop="url" rel="index"><span itemprop="name">redis</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/redis/redis/" class="leancloud_visitors" data-flag-title="redis配置">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <h1 id="规划"><a href="#规划" class="headerlink" title="规划"></a>规划</h1><p>共6个应用</p>
<p>1个master,2个slave,3个sentinel</p>
<p>master : 192.168.1.110 6379</p>
<p>slave1: 192.168.1.110 6380</p>
<p>slave2: 192.168.1.110 6381</p>
<p>sentinel1: 192.168.1.110 26379</p>
<p>sentinel2: 192.168.1.110 26380</p>
<p>sentinel3: 192.168.1.110 26381</p>
<h1 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h1><p>redis目录</p>
<p>/usr/local/bin/</p>
<p>配置文件目录</p>
<p>/media/sf_linux/soft/redis</p>
<p>该目录下新建6个conf文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7 redis]# pwd</span><br><span class="line">/media/sf_linux/soft/redis</span><br><span class="line">[root@centos7 redis]# ll</span><br><span class="line">total 89</span><br><span class="line">drwxrwx---. 1 root vboxsf  4096 Jan 31 14:15 logs</span><br><span class="line">-rwxrwx---. 1 root vboxsf   327 Jan 31 14:14 redis6379.conf</span><br><span class="line">-rwxrwx---. 1 root vboxsf   177 Jan 31 14:47 redis6380.conf</span><br><span class="line">-rwxrwx---. 1 root vboxsf   203 Jan 31 14:47 redis6381.conf</span><br><span class="line">-rwxrwx---. 1 root vboxsf 62155 Nov 22 18:26 redis.conf.bak</span><br><span class="line">-rwxrwx---. 1 root vboxsf   803 Jan 31 14:18 sentinel26379.conf</span><br><span class="line">-rwxrwx---. 1 root vboxsf   708 Jan 31 14:47 sentinel26380.conf</span><br><span class="line">-rwxrwx---. 1 root vboxsf   708 Jan 31 14:47 sentinel26381.conf</span><br></pre></td></tr></table></figure>
<p>日志目录</p>
<p>/media/sf_linux/soft/redis/logs</p>
<p>数据目录</p>
<p>/opt/redis/data/</p>
<p>临时目录</p>
<p>/opt/redis/data/</p>
<p>创建目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mkdir /opt/redis/data/</span><br><span class="line">mkdir /opt/redis/data/temp</span><br><span class="line">mkdir /media/sf_linux/soft/redis/logs</span><br><span class="line">mkdir /media/sf_linux/soft/redis</span><br></pre></td></tr></table></figure>
<h1 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h1><h2 id="master"><a href="#master" class="headerlink" title="master"></a>master</h2><p>redis6379.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">#访问ip</span><br><span class="line">bind 192.168.1.110</span><br><span class="line">#工作目录</span><br><span class="line">#不知道什么原因如果目录配置在/media/sf_linux下,sentinel无法生成文件,所以换个目录,可能是因为/media/sf_linux是windows的映射目录</span><br><span class="line">dir &quot;/opt/redis/data&quot;</span><br><span class="line">#dump文件名</span><br><span class="line">dbfilename &quot;dump6379.rdb&quot;</span><br><span class="line">#端口</span><br><span class="line">port 6379</span><br><span class="line">#日志文件</span><br><span class="line">logfile &quot;/media/sf_linux/soft/redis/logs/6379.log&quot;</span><br><span class="line">#后台方式启动</span><br><span class="line">daemonize yes</span><br></pre></td></tr></table></figure>
<h2 id="slave1"><a href="#slave1" class="headerlink" title="slave1"></a>slave1</h2><p>redis6380.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">bind 192.168.1.110</span><br><span class="line">dir &quot;/opt/redis/data&quot;</span><br><span class="line">daemonize yes</span><br><span class="line">#dump文件名,端口,日志文件改为6380</span><br><span class="line">dbfilename &quot;dump6380.rdb&quot;</span><br><span class="line">port 6380</span><br><span class="line">logfile &quot;/media/sf_linux/soft/redis/logs/6380.log&quot;</span><br><span class="line">slaveof 192.168.1.110 6379</span><br></pre></td></tr></table></figure>
<h2 id="slave2"><a href="#slave2" class="headerlink" title="slave2"></a>slave2</h2><p>redis6381.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">bind 192.168.1.110</span><br><span class="line">dir &quot;/opt/redis/data&quot;</span><br><span class="line">daemonize yes</span><br><span class="line">#dump文件名,端口,日志文件改为6381</span><br><span class="line">dbfilename &quot;dump6381.rdb&quot;</span><br><span class="line">port 6381</span><br><span class="line">logfile &quot;/media/sf_linux/soft/redis/logs/6381.log&quot;</span><br><span class="line">slaveof 192.168.1.110 6379</span><br></pre></td></tr></table></figure>
<h2 id="sentinel1"><a href="#sentinel1" class="headerlink" title="sentinel1"></a>sentinel1</h2><p>sentinel26379.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">bind 192.168.1.110</span><br><span class="line">port 26379</span><br><span class="line">daemonize yes</span><br><span class="line">logfile &quot;/media/sf_linux/soft/redis/logs/sentia26379.log&quot;</span><br><span class="line">dir &quot;/opt/redis/data/temp&quot;</span><br><span class="line">#master名称叫mymaster,java应用里需要用到这个名字</span><br><span class="line">#1只要有1个sentinel认为服务器挂了就切换</span><br><span class="line">sentinel monitor mymaster 192.168.1.110 6379 1</span><br><span class="line">#10000,服务器挂掉10秒后切换</span><br><span class="line">sentinel down-after-milliseconds mymaster 10000</span><br></pre></td></tr></table></figure>
<h2 id="sentinel2"><a href="#sentinel2" class="headerlink" title="sentinel2"></a>sentinel2</h2><p>sentinel26380.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">bind 192.168.1.110</span><br><span class="line">daemonize yes</span><br><span class="line">dir &quot;/opt/redis/data/temp&quot;</span><br><span class="line">sentinel monitor mymaster 192.168.1.110 6379 1</span><br><span class="line">sentinel down-after-milliseconds mymaster 10000</span><br><span class="line">#端口和日志改为26380</span><br><span class="line">port 26380</span><br><span class="line">logfile &quot;/media/sf_linux/soft/redis/logs/sential26380.log&quot;</span><br></pre></td></tr></table></figure>
<h2 id="sentinel3"><a href="#sentinel3" class="headerlink" title="sentinel3"></a>sentinel3</h2><p>sentinel26381.conf</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">bind 192.168.1.110</span><br><span class="line">daemonize yes</span><br><span class="line">dir &quot;/opt/redis/data/temp&quot;</span><br><span class="line">sentinel monitor mymaster 192.168.1.110 6379 1</span><br><span class="line">sentinel down-after-milliseconds mymaster 10000</span><br><span class="line">#端口和日志改为26381</span><br><span class="line">port 26381</span><br><span class="line">logfile &quot;/media/sf_linux/soft/redis/logs/sential26381.log&quot;</span><br></pre></td></tr></table></figure>
<h1 id="启动"><a href="#启动" class="headerlink" title="启动"></a>启动</h1><h2 id="redis"><a href="#redis" class="headerlink" title="redis"></a>redis</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/bin/redis-server /media/sf_linux/soft/redis/redis6379.conf </span><br><span class="line">/usr/local/bin/redis-server /media/sf_linux/soft/redis/redis6380.conf </span><br><span class="line">/usr/local/bin/redis-server /media/sf_linux/soft/redis/redis6381.conf</span><br></pre></td></tr></table></figure>
<h2 id="sentinel"><a href="#sentinel" class="headerlink" title="sentinel"></a>sentinel</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/usr/local/bin/redis-sentinel /media/sf_linux/soft/redis/sentinel26379.conf </span><br><span class="line">/usr/local/bin/redis-sentinel /media/sf_linux/soft/redis/sentinel26380.conf </span><br><span class="line">/usr/local/bin/redis-sentinel /media/sf_linux/soft/redis/sentinel26381.conf</span><br></pre></td></tr></table></figure>
<h2 id="查看"><a href="#查看" class="headerlink" title="查看"></a>查看</h2><p>ps -ef|grep redis</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7 ~]# ps -ef|grep redis</span><br><span class="line">root     13041     1  0 14:14 ?        00:00:00 /usr/local/bin/redis-server 192.168.1.110:6379</span><br><span class="line">root     13054     1  0 14:14 ?        00:00:00 /usr/local/bin/redis-server 192.168.1.110:6380</span><br><span class="line">root     13063     1  0 14:14 ?        00:00:00 /usr/local/bin/redis-server 192.168.1.110:6381</span><br><span class="line">root     13270     1  0 14:17 ?        00:00:00 /usr/local/bin/redis-sentinel 192.168.1.110:26379 [sentinel]</span><br><span class="line">root     13278     1  0 14:18 ?        00:00:00 /usr/local/bin/redis-sentinel 192.168.1.110:26380 [sentinel]</span><br><span class="line">root     13285     1  0 14:18 ?        00:00:00 /usr/local/bin/redis-sentinel 192.168.1.110:26381 [sentinel]</span><br><span class="line">root     13350 11045  0 14:19 pts/0    00:00:00 grep --color=auto redis</span><br></pre></td></tr></table></figure>
<h1 id="java"><a href="#java" class="headerlink" title="java"></a>java</h1><h2 id="所需jar包"><a href="#所需jar包" class="headerlink" title="所需jar包"></a>所需jar包</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"> <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>redis.clients<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>jedis<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.7.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="测试redis"><a href="#测试redis" class="headerlink" title="测试redis"></a>测试redis</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> xxx.xxx;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.Jedis;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RedisTest</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String args[])</span></span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"--------master-----------"</span>);</span><br><span class="line">        Jedis master=<span class="keyword">new</span> Jedis(<span class="string">"192.168.1.110"</span>,<span class="number">6379</span>);</span><br><span class="line">        master.set(<span class="string">"hello"</span>,<span class="string">"redis"</span>);</span><br><span class="line">        String message=master.get(<span class="string">"hello"</span>);</span><br><span class="line">        System.out.println(<span class="string">"hello "</span>+message);</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">"--------slave-----------"</span>);</span><br><span class="line">        Jedis slave1=<span class="keyword">new</span> Jedis(<span class="string">"192.168.1.110"</span>,<span class="number">6380</span>);</span><br><span class="line">        slave1.set(<span class="string">"hello"</span>,<span class="string">"redis"</span>);<span class="comment">//这里报错</span></span><br><span class="line">        message=slave1.get(<span class="string">"hello"</span>);</span><br><span class="line">        System.out.println(<span class="string">"hello "</span>+message);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>运行结果</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">--------master-----------</span><br><span class="line">hello redis</span><br><span class="line">--------slave-----------</span><br><span class="line">Exception in thread &quot;main&quot; redis.clients.jedis.exceptions.JedisDataException: READONLY You can&apos;t write against a read only slave.</span><br><span class="line">	at redis.clients.jedis.Protocol.processError(Protocol.java:117)</span><br><span class="line">	at redis.clients.jedis.Protocol.process(Protocol.java:142)</span><br><span class="line">	at redis.clients.jedis.Protocol.read(Protocol.java:196)</span><br><span class="line">	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:288)</span><br><span class="line">	at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:187)</span><br><span class="line">	at redis.clients.jedis.Jedis.set(Jedis.java:66)</span><br><span class="line">	at wang.wangby.redis.RedisTest.main(RedisTest.java:14)</span><br></pre></td></tr></table></figure>
<h2 id="测试集群"><a href="#测试集群" class="headerlink" title="测试集群"></a>测试集群</h2><h3 id="正常访问"><a href="#正常访问" class="headerlink" title="正常访问"></a>正常访问</h3><p>每1秒访问一次redis集群，get and set 1个变量（no）的值，然后将这个值+1</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> wang.wangby.redis;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.Jedis;</span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.JedisPoolConfig;</span><br><span class="line"><span class="keyword">import</span> redis.clients.jedis.JedisSentinelPool;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.util.HashSet;</span><br><span class="line"><span class="keyword">import</span> java.util.Set;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SentinelsTest</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String args[])</span> </span>&#123;</span><br><span class="line">        JedisPoolConfig config = <span class="keyword">new</span> JedisPoolConfig();</span><br><span class="line">        config.setMaxTotal(<span class="number">100</span>);<span class="comment">//最大连接数</span></span><br><span class="line">        config.setMaxWaitMillis(<span class="number">60000</span>);<span class="comment">// 设置最大阻塞时间，</span></span><br><span class="line">        config.setMaxIdle(<span class="number">10</span>);<span class="comment">// 设置空间连接</span></span><br><span class="line">        Set&lt;String&gt; sentinels = <span class="keyword">new</span> HashSet&lt;String&gt;();</span><br><span class="line">        sentinels.add(<span class="string">"192.168.1.110:26379"</span>);</span><br><span class="line">        sentinels.add(<span class="string">"192.168.1.110:26380"</span>);</span><br><span class="line">        sentinels.add(<span class="string">"192.168.1.110:26381"</span>);</span><br><span class="line">        JedisSentinelPool pool = <span class="keyword">new</span> JedisSentinelPool(<span class="string">"mymaster"</span>, sentinels, config);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">int</span> no=<span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span> (<span class="keyword">true</span>) &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                Jedis jedis = pool.getResource();</span><br><span class="line">                no++;</span><br><span class="line">                jedis.set(<span class="string">"count"</span>, no+<span class="string">""</span>);</span><br><span class="line">                jedis.close();</span><br><span class="line">                System.out.println(<span class="string">"count: "</span>+jedis.get(<span class="string">"count"</span>));</span><br><span class="line">                Thread.sleep(<span class="number">1000</span>);</span><br><span class="line">            &#125; <span class="keyword">catch</span> (Exception ex) &#123;</span><br><span class="line">                System.out.println(ex.getMessage());</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>输出</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">count: 1</span><br><span class="line">count: 2</span><br><span class="line">count: 3</span><br><span class="line">count: 4</span><br><span class="line">...</span><br></pre></td></tr></table></figure>
<h3 id="模拟sentinel挂掉"><a href="#模拟sentinel挂掉" class="headerlink" title="模拟sentinel挂掉"></a>模拟sentinel挂掉</h3><p>kill</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7 ~]# lsof -i:26379|awk 'NR==2&#123;print $2&#125;' </span><br><span class="line">13270</span><br><span class="line">[root@centos7 ~]# kill 13270</span><br></pre></td></tr></table></figure>
<h4 id="控制台"><a href="#控制台" class="headerlink" title="控制台"></a>控制台</h4><p>报出警告，但数据仍能正常访问</p>
<figure class="highlight verilog"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">count: <span class="number">338</span></span><br><span class="line">count: <span class="number">339</span></span><br><span class="line">count: <span class="number">340</span></span><br><span class="line">count: <span class="number">341</span></span><br><span class="line">一月 <span class="number">31</span>, <span class="number">2019</span> <span class="number">2</span>:<span class="number">44</span>:<span class="number">59</span> 下午 redis<span class="variable">.clients</span><span class="variable">.jedis</span><span class="variable">.JedisSentinelPool</span>$MasterListener run</span><br><span class="line">严重: Lost connection to Sentinel at <span class="number">192</span><span class="variable">.168</span><span class="variable">.1</span><span class="variable">.110</span>:<span class="number">26379</span>. Sleeping <span class="number">5000</span>ms <span class="keyword">and</span> retrying.</span><br><span class="line">count: <span class="number">342</span></span><br><span class="line">count: <span class="number">343</span></span><br><span class="line">count: <span class="number">344</span></span><br></pre></td></tr></table></figure>
<h3 id="模拟master挂掉"><a href="#模拟master挂掉" class="headerlink" title="模拟master挂掉"></a>模拟master挂掉</h3><p>kill</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">[root@centos7 ~]# lsof -i:6379|awk 'NR==2&#123;print $2&#125;' </span><br><span class="line">13041</span><br><span class="line">[root@centos7 ~]# kill 13041</span><br><span class="line">[root@centos7 ~]#</span><br></pre></td></tr></table></figure>
<h4 id="控制台-1"><a href="#控制台-1" class="headerlink" title="控制台"></a>控制台</h4><p>有10秒钟无法访问redis(Could not get a resource from the pool)，10秒后恢复正常</p>
<figure class="highlight verilog"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">count: <span class="number">482</span></span><br><span class="line">count: <span class="number">483</span></span><br><span class="line">Unexpected <span class="keyword">end</span> of stream.</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">一月 <span class="number">31</span>, <span class="number">2019</span> <span class="number">2</span>:<span class="number">47</span>:<span class="number">24</span> 下午 redis<span class="variable">.clients</span><span class="variable">.jedis</span><span class="variable">.JedisSentinelPool</span>$MasterListener run</span><br><span class="line">严重: Lost connection to Sentinel at <span class="number">192</span><span class="variable">.168</span><span class="variable">.1</span><span class="variable">.110</span>:<span class="number">26379</span>. Sleeping <span class="number">5000</span>ms <span class="keyword">and</span> retrying.</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">一月 <span class="number">31</span>, <span class="number">2019</span> <span class="number">2</span>:<span class="number">47</span>:<span class="number">30</span> 下午 redis<span class="variable">.clients</span><span class="variable">.jedis</span><span class="variable">.JedisSentinelPool</span>$MasterListener run</span><br><span class="line">严重: Lost connection to Sentinel at <span class="number">192</span><span class="variable">.168</span><span class="variable">.1</span><span class="variable">.110</span>:<span class="number">26379</span>. Sleeping <span class="number">5000</span>ms <span class="keyword">and</span> retrying.</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">一月 <span class="number">31</span>, <span class="number">2019</span> <span class="number">2</span>:<span class="number">47</span>:<span class="number">33</span> 下午 redis<span class="variable">.clients</span><span class="variable">.jedis</span><span class="variable">.JedisSentinelPool</span> initPool</span><br><span class="line">信息: Created JedisPool to master at <span class="number">192</span><span class="variable">.168</span><span class="variable">.1</span><span class="variable">.110</span>:<span class="number">6380</span></span><br><span class="line">Could <span class="keyword">not</span> get a resource from the pool</span><br><span class="line">count: <span class="number">485</span></span><br><span class="line">count: <span class="number">486</span></span><br><span class="line">count: <span class="number">487</span></span><br><span class="line">一月 <span class="number">31</span>, <span class="number">2019</span> <span class="number">2</span>:<span class="number">47</span>:<span class="number">36</span> 下午 redis<span class="variable">.clients</span><span class="variable">.jedis</span><span class="variable">.JedisSentinelPool</span>$MasterListener run</span><br><span class="line">严重: Lost connection to Sentinel at <span class="number">192</span><span class="variable">.168</span><span class="variable">.1</span><span class="variable">.110</span>:<span class="number">26379</span>. Sleeping <span class="number">5000</span>ms <span class="keyword">and</span> retrying.</span><br><span class="line">count: <span class="number">488</span></span><br><span class="line">count: <span class="number">489</span></span><br></pre></td></tr></table></figure>
<h4 id="配置文件"><a href="#配置文件" class="headerlink" title="配置文件"></a>配置文件</h4><p>redis6381.conf的最后一行slaveof从6379变更为6380</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">slaveof 192.168.1.110 6380</span><br></pre></td></tr></table></figure>
<p>redis6381.conf文件后面的slaveof被删掉了</p>
<p>所有sentinel的monitor自动变更为6380</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sentinel monitor mymaster 192.168.1.110 6380 1</span><br></pre></td></tr></table></figure>
<p>重启6379后</p>
<p>redis6381.conf文件末尾自动加上</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># Generated by CONFIG REWRITE</span><br><span class="line">slaveof 192.168.1.110 6380</span><br></pre></td></tr></table></figure>
<h1 id="监控"><a href="#监控" class="headerlink" title="监控"></a>监控</h1><h2 id="日志"><a href="#日志" class="headerlink" title="日志"></a>日志</h2><p>jedis 使用java.util.logging，日志格式和现有监控系统不一样，需要手动修改一下</p>
<p>日志级别 java.util.logging.Level</p>
<table>
<thead>
<tr>
<th>SEVERE</th>
<th>WARNING</th>
<th>INFO</th>
<th>CONFIG</th>
<th>FINE</th>
<th>FINER</th>
<th>FINEST</th>
</tr>
</thead>
<tbody>
<tr>
<td>严重</td>
<td>警告</td>
<td>信息</td>
<td>——</td>
<td>—-</td>
<td>—–</td>
<td>——</td>
</tr>
</tbody>
</table>
<p>在根目录创建logging.propertie</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">handlers= java.util.logging.ConsoleHandler</span><br><span class="line">java.util.logging.ConsoleHandler.level = INFO</span><br><span class="line">java.util.logging.ConsoleHandler.formatter =wang.wangby.redis.MyFormat</span><br></pre></td></tr></table></figure>
<p>程序启动的时候加载</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">java.util.logging.LogManager logManager = java.util.logging.LogManager.getLogManager();</span><br><span class="line">InputStream input=LogTest.class.getResourceAsStream(<span class="string">"/logging.properties"</span>);</span><br><span class="line">logManager.readConfiguration(input);</span><br></pre></td></tr></table></figure>
<p>自定义format类（继承java.util.logging.Formatter实现format方法）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">// @see java.util.logging.SimpleFormatter#format;</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MyFormat</span> <span class="keyword">extends</span> <span class="title">Formatter</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">format</span><span class="params">(LogRecord record)</span> </span>&#123;</span><br><span class="line">        String source;</span><br><span class="line">        <span class="keyword">if</span> (record.getSourceClassName() != <span class="keyword">null</span>) &#123;</span><br><span class="line">            String fullName = record.getSourceClassName();</span><br><span class="line">            <span class="keyword">int</span> point = fullName.lastIndexOf(<span class="string">"."</span>);</span><br><span class="line">            <span class="keyword">if</span> (point != -<span class="number">1</span>) &#123;</span><br><span class="line">                source = fullName.substring(point + <span class="number">1</span>);</span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                source = fullName;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">if</span> (record.getSourceMethodName() != <span class="keyword">null</span>) &#123;</span><br><span class="line">                source += <span class="string">"."</span> + record.getSourceMethodName();</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            source = record.getLoggerName();</span><br><span class="line">        &#125;</span><br><span class="line">        String message = formatMessage(record);</span><br><span class="line">        String throwable = <span class="string">""</span>;</span><br><span class="line">        <span class="keyword">if</span> (record.getThrown() != <span class="keyword">null</span>) &#123;</span><br><span class="line">            StringWriter sw = <span class="keyword">new</span> StringWriter();</span><br><span class="line">            PrintWriter pw = <span class="keyword">new</span> PrintWriter(sw);</span><br><span class="line">            pw.println();</span><br><span class="line">            record.getThrown().printStackTrace(pw);</span><br><span class="line">            pw.close();</span><br><span class="line">            throwable = sw.toString();</span><br><span class="line">        &#125;</span><br><span class="line">       </span><br><span class="line">        String data = DateTime.current(DateTime.YEAR_TO_MILLISECOND).toString();</span><br><span class="line">        <span class="keyword">return</span> data + <span class="string">" "</span> + record.getLevel() + <span class="string">" "</span> + source + <span class="string">" "</span> + message + <span class="string">" "</span> + throwable + <span class="string">"\n"</span>;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/redis/redis/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/ops/ops/常用命令/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/ops/ops/常用命令/" itemprop="url">
                  常用命令
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-07-29 20:27:18" itemprop="dateCreated datePublished" datetime="2018-07-29T20:27:18+08:00">2018-07-29</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-01-30 19:37:28" itemprop="dateModified" datetime="2019-01-30T19:37:28+08:00">2019-01-30</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/ops/" itemprop="url" rel="index"><span itemprop="name">ops</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/ops/ops/常用命令/" class="leancloud_visitors" data-flag-title="常用命令">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>日常开发经常会碰到，但过阵子又忘记了的命令，做一个备份，便于搜索，不断更新中。。。</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/ops/ops/常用命令/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/code/java/多线程/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/code/java/多线程/" itemprop="url">
                  多线程
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-07-30 18:01:30" itemprop="dateCreated datePublished" datetime="2018-07-30T18:01:30+08:00">2018-07-30</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-01-25 07:29:49" itemprop="dateModified" datetime="2019-01-25T07:29:49+08:00">2019-01-25</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/code/" itemprop="url" rel="index"><span itemprop="name">code</span></a></span>

                
                
                  ，
                
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/code/java/" itemprop="url" rel="index"><span itemprop="name">java</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/code/java/多线程/" class="leancloud_visitors" data-flag-title="多线程">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>多线程个人理解</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/code/java/多线程/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/code/日志收集器/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/code/日志收集器/" itemprop="url">
                  日志收集器
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2019-01-15 17:38:20" itemprop="dateCreated datePublished" datetime="2019-01-15T17:38:20+08:00">2019-01-15</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-01-19 10:16:07" itemprop="dateModified" datetime="2019-01-19T10:16:07+08:00">2019-01-19</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/code/" itemprop="url" rel="index"><span itemprop="name">code</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/code/日志收集器/" class="leancloud_visitors" data-flag-title="日志收集器">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <h1 id="系统概述"><a href="#系统概述" class="headerlink" title="系统概述"></a>系统概述</h1><p>主要功能，根据配置读取指定服务器上的日志，格式化后发送到日志中心</p>
<h2 id="用到的第三方系统"><a href="#用到的第三方系统" class="headerlink" title="用到的第三方系统"></a>用到的第三方系统</h2><h3 id="springboot-2-0-3-RELEASE"><a href="#springboot-2-0-3-RELEASE" class="headerlink" title="springboot-2.0.3.RELEASE"></a>springboot-2.0.3.RELEASE</h3><p>​    项目是web工程，使用内嵌tomcat方式，页面转发使用springmvc</p>
<h3 id="elasticsearch-6-3-0"><a href="#elasticsearch-6-3-0" class="headerlink" title="elasticsearch-6.3.0"></a>elasticsearch-6.3.0</h3><p>​    持久化用的是elasticsearch，如何读取日志相关的配置信息都放在elasticsearch上。读到的日志默认也是存到elasticsearch里面</p>
<h3 id="httpclient-4-5-5"><a href="#httpclient-4-5-5" class="headerlink" title="httpclient-4.5.5"></a>httpclient-4.5.5</h3><p>​    和elasticsearch通信全部走的是restful接口，用httpclient进行通讯</p>
<h3 id="druid-1-1-9"><a href="#druid-1-1-9" class="headerlink" title="druid-1.1.9"></a>druid-1.1.9</h3><p>​    查询的时候页面传进来的是sql语句，用druid的sql parser模块解析sql语句，转为elasticsearch的DSL</p>
<h3 id="ace-editor"><a href="#ace-editor" class="headerlink" title="ace-editor"></a>ace-editor</h3><p>​    为了方便用户编写sql，引入了ace-editor作为在线编辑器</p>
<h3 id="velocity"><a href="#velocity" class="headerlink" title="velocity"></a>velocity</h3><p>​    模板引擎，当需要返回页面时用velocity解析</p>
<h2 id="约定"><a href="#约定" class="headerlink" title="约定"></a>约定</h2><p>​    根据convention over configuration原则，编码风格大部分采用springboot的方式，还有一些自定义规则，在不影响性能的前提下，同类型代码尽量采用同一套标准。</p>
<p>​    这些规则只是一些人为规定，无所谓好或不好，只是为了查找代码方便。当系统出现bug的时候，特定命名规则下的类行为基本可以预测，调试时可以大大加快效率。</p>
<h3 id="命名规则"><a href="#命名规则" class="headerlink" title="命名规则"></a>命名规则</h3><p>所有的包均采用这种行形式</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wang.wangby.$&#123;项目&#125;.类型</span><br><span class="line">wang.wangby.$&#123;项目&#125;.$&#123;子项目&#125;.类型</span><br></pre></td></tr></table></figure>
<h3 id="特殊的包名"><a href="#特殊的包名" class="headerlink" title="特殊的包名"></a>特殊的包名</h3><p>一些特定的包名下只能存放指定的类，这些类均有自己的特殊功能。不是这些功能的类，不允许放在这下面</p>
<h4 id="model"><a href="#model" class="headerlink" title="model"></a>model</h4><h5 id="格式"><a href="#格式" class="headerlink" title="格式"></a>格式</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wang.wangby.$&#123;项目&#125;.model.XXX.XXX</span><br><span class="line">wang.wangby.$&#123;项目&#125;.$&#123;子项目&#125;.model.XXX.xxX</span><br></pre></td></tr></table></figure>
<h5 id="功能"><a href="#功能" class="headerlink" title="功能"></a>功能</h5><p>​    封装参数，Controller和service，service和dao之间只能传递基本类型和model类</p>
<h5 id="约定-1"><a href="#约定-1" class="headerlink" title="约定"></a>约定</h5><ol>
<li>所有model均实现了wang.wangby.model.Dto接口</li>
<li>类名都添加了标签@Data</li>
<li>所有model类都必须有且只有1个主键，主键上加了注解@wang.wangby.annotation.persistence.Id</li>
<li>内部不允许调使用任何非java或wang.wangby.utils开头的类</li>
<li>不允许添加get和set方法，需要的话直接添加属性</li>
<li>新增的public方法只能是无参的</li>
<li>一个项目下的model不允许重名，不论包名是否一样</li>
</ol>
<h4 id="model-vo"><a href="#model-vo" class="headerlink" title="model.vo"></a>model.vo</h4><h5 id="格式-1"><a href="#格式-1" class="headerlink" title="格式"></a>格式</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wang.wangby.$&#123;项目&#125;.model.vo.XXX.XXX</span><br><span class="line">wang.wangby.$&#123;项目&#125;.$&#123;子项目&#125;.model.vo.XXX.XXX</span><br></pre></td></tr></table></figure>
<h5 id="功能-1"><a href="#功能-1" class="headerlink" title="功能"></a>功能</h5><p>​    封装那些需要在各层之间传输，但没有主键，不需要持久化的对象。可以不实现dto接口</p>
<h5 id="约定-2"><a href="#约定-2" class="headerlink" title="约定"></a>约定</h5><p>​    和model类一样，只不过没有主键</p>
<h4 id="controller"><a href="#controller" class="headerlink" title="controller"></a>controller</h4><h5 id="格式-2"><a href="#格式-2" class="headerlink" title="格式"></a>格式</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wang.wangby.$&#123;项目&#125;.controller.XXX</span><br><span class="line">wang.wangby.$&#123;项目&#125;.$&#123;子项目&#125;.controller.XXX</span><br></pre></td></tr></table></figure>
<h5 id="功能-2"><a href="#功能-2" class="headerlink" title="功能"></a>功能</h5><p>​    处理请求的url，返回页面或者json</p>
<h5 id="约定-3"><a href="#约定-3" class="headerlink" title="约定"></a>约定</h5><ol>
<li>类名均叫xxxController</li>
<li>一个项目下Controller不能重名，不论包名是否一样</li>
<li>全部继承自wang.wangby.controller.BaseController</li>
<li>类上全部加了注解@RestController</li>
<li>类上全部加了注解@RequestMapping，并且value=xxx</li>
<li>所有方法均标记@RequestMapping，value和方法名一样，方法不允许重载</li>
<li>返回值<ol>
<li>需要返回json的时候，返回值全部放在Response.data里面</li>
<li>需要返回页面的时候，直接用velocity解析然后返回string</li>
</ol>
</li>
</ol>
<h4 id="service"><a href="#service" class="headerlink" title="service"></a>service</h4><h5 id="格式-3"><a href="#格式-3" class="headerlink" title="格式"></a>格式</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">wang.wangby.$&#123;项目&#125;.service.XXX</span><br><span class="line">wang.wangby.$&#123;项目&#125;.$&#123;子项目&#125;.service.XXX</span><br></pre></td></tr></table></figure>
<h5 id="功能-3"><a href="#功能-3" class="headerlink" title="功能"></a>功能</h5><p>​    处理业务逻辑，如需事务设置在这层</p>
<h5 id="约定-4"><a href="#约定-4" class="headerlink" title="约定"></a>约定</h5><ol>
<li>service包下的所有类均叫xxxService</li>
<li>类上全部加了注解@org.springframework.stereotype.Service</li>
<li>所有属性只通过@Autowired注解注入</li>
</ol>
<h3 id="页面映射规则"><a href="#页面映射规则" class="headerlink" title="页面映射规则"></a>页面映射规则</h3><h4 id="controller请求"><a href="#controller请求" class="headerlink" title="controller请求"></a>controller请求</h4><p>所有从controller请求格式都是这样的</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">/xxx/method</span><br><span class="line">/子项目/xxx/method</span><br></pre></td></tr></table></figure>
<p>每个url规定都由xxxController.method处理</p>
<p>url确定了，返回的视图也是固定的，/src/main/java/resources/templates/xxx/method.html，如果有子项目就是/src/main/java/resources/templates/子项目/xxx/method.html</p>
<h4 id="静态资源"><a href="#静态资源" class="headerlink" title="静态资源"></a>静态资源</h4><p>静态资源全部放在/src/main/java/resources</p>
<h5 id="样式文件"><a href="#样式文件" class="headerlink" title="样式文件"></a>样式文件</h5><p>/src/main/java/resources/css</p>
<h5 id="图片"><a href="#图片" class="headerlink" title="图片"></a>图片</h5><p>/src/main/java/resources/img</p>
<h5 id="js"><a href="#js" class="headerlink" title="js"></a>js</h5><p>/src/main/java/resources/js    </p>
<p>所有引入js的代码均在/src/main/java/resources/js/importJs.js    </p>
<h1 id="开始编码"><a href="#开始编码" class="headerlink" title="开始编码"></a>开始编码</h1><h2 id="初始化项目"><a href="#初始化项目" class="headerlink" title="初始化项目"></a>初始化项目</h2><h3 id="新增目录"><a href="#新增目录" class="headerlink" title="新增目录"></a>新增目录</h3><p><img src="/blog/images/1547851272684.png" alt="1547851204686">    </p>
<p>log-collector：项目跟路径</p>
<p>​    src</p>
<p>​        main</p>
<p>​            java：源代码</p>
<p>​            resources：资源文件</p>
<p>​                static：静态资源</p>
<p>​                templates：页面</p>
<p>​        test</p>
<p>​            java：测试代码</p>
<h3 id="添加pom-xml"><a href="#添加pom-xml" class="headerlink" title="添加pom.xml"></a>添加pom.xml</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">project</span> <span class="attr">xmlns</span>=<span class="string">"http://maven.apache.org/POM/4.0.0"</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span></span></span><br><span class="line"><span class="tag">         <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">modelVersion</span>&gt;</span>4.0.0<span class="tag">&lt;/<span class="name">modelVersion</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>log-collector<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>wang.wangby<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>web-parent<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>0.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>wang.wangby<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>webapp-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;my.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line">        <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-configuration-processor<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br><span class="line"></span><br><span class="line">    <span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-maven-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">executions</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">execution</span>&gt;</span></span><br><span class="line">                        <span class="tag">&lt;<span class="name">goals</span>&gt;</span></span><br><span class="line">                            <span class="tag">&lt;<span class="name">goal</span>&gt;</span>repackage<span class="tag">&lt;/<span class="name">goal</span>&gt;</span></span><br><span class="line">                        <span class="tag">&lt;/<span class="name">goals</span>&gt;</span></span><br><span class="line">                    <span class="tag">&lt;/<span class="name">execution</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">executions</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">project</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="web-parent"><a href="#web-parent" class="headerlink" title="web-parent"></a>web-parent</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">parent</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">groupId</span>&gt;</span>wang.wangby<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>web-parent<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">version</span>&gt;</span>0.1<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">parent</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>web-parent继承自<code>org.springframework.boot:spring-boot-dependencies:2.0.3.RELEASE</code>指定了一些常用的第三jar包的版本号，所有导入第三方jar是通常不需要写版本号</p>
<p>对于自己编写的项目，统一用${my.version}</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>wang.wangby<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>XXX-XXX<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;my.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h4 id="base-test"><a href="#base-test" class="headerlink" title="base-test"></a>base-test</h4><p>继承的同时还自动引入了，scrop为test</p>
<p>测试工具包，引入了powermock，提供了一些测试常用的功能</p>
<p>格式化判断字符串是否相等</p>
<p>并发执行代码</p>
<p>脱离spirng容器初始化对象</p>
<p>…</p>
<p>编写testcase的时候继承TestBase就好</p>
<p>默认scope是test</p>
<h4 id="webapp-starter"><a href="#webapp-starter" class="headerlink" title="webapp-starter"></a>webapp-starter</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>wang.wangby<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>webapp-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;my.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>引入web工程所需的包和一些默认配置，具体有</p>
<h5 id="spring-mvc"><a href="#spring-mvc" class="headerlink" title="spring-mvc"></a>spring-mvc</h5><ol>
<li><p>默认json解析改用fastJson</p>
<ol>
<li>BigInteger和Long均输出字符串</li>
<li>忽略所有null字段</li>
<li>日期按毫秒形式出书</li>
</ol>
</li>
<li><p>拦截所有返回值的是Response对象的方法，如果出异常了，就拦截并且返回Response.fail(ex.getMessage());</p>
</li>
<li><p>字符串和日期的转换类换成wang.wangby.springboot.autoconfigure.mvc.StringToDateConverter</p>
<ol>
<li>允许格式yyyy-MM-dd HH:mm:ss|yyyy-MM-dd|纯数字</li>
</ol>
</li>
</ol>
<p>#####web相关</p>
<p>my.webfilter.enable=true就添加一些httpfilter</p>
<ol>
<li>wang.wangby.web.webfilter.QueueFilter：限制系统允许的最大并发数，超过数量直接返回默认字符串</li>
<li>wang.wangby.web.webfilter.StatistFilter：统计每个请求耗时</li>
</ol>
<p>#####页面相关</p>
<p>初始化了velocity引擎，使用时调用wang.wangby.utils.template.TemplateUtil里的方法就好了</p>
<p>前端框引入了bootstrap和jquery</p>
<h4 id="spring-boot-configuration-processor"><a href="#spring-boot-configuration-processor" class="headerlink" title="spring-boot-configuration-processor"></a>spring-boot-configuration-processor</h4><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-configuration-processor<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">optional</span>&gt;</span>true<span class="tag">&lt;/<span class="name">optional</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>spring提供的工具类，引入这个jar后，在项目里修改application.yaml就会有提示了</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/code/日志收集器/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/web/URI和URL区别/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="我的云笔记">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/blog/web/URI和URL区别/" itemprop="url">
                  URI和URL
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">

            
            
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              

              
                
              

              <time title="创建时间：2018-07-30 18:01:30" itemprop="dateCreated datePublished" datetime="2018-07-30T18:01:30+08:00">2018-07-30</time>
            

            
              

              
                
                <span class="post-meta-divider">|</span>
                

                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                
                  <span class="post-meta-item-text">更新于</span>
                
                <time title="修改时间：2019-01-19 08:21:07" itemprop="dateModified" datetime="2019-01-19T08:21:07+08:00">2019-01-19</time>
              
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/blog/categories/web/" itemprop="url" rel="index"><span itemprop="name">web</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/blog/web/URI和URL区别/" class="leancloud_visitors" data-flag-title="URI和URL">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数：</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          <p>URI和URL区别</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/blog/web/URI和URL区别/#more" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>

    

    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/blog/">1</a><span class="page-number current">2</span><a class="page-number" href="/blog/page/3/">3</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/6/">6</a><a class="extend next" rel="next" href="/blog/page/3/"><i class="fa fa-angle-right" aria-label="下一页"></i></a>
  </nav>



          </div>
          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name"></p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/blog/archives">
                
                    <span class="site-state-item-count">54</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/blog/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">25</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/blog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">45</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          

          
          

          
          

          
            
          
          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder"></span>

  

  
</div>




  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://theme-next.org">NexT.Pisces</a> v6.3.0</div>





<span id="busuanzi_container_site_uv">
  &nbsp;<span id="busuanzi_value_site_uv"></span>
</span>

<span>/</span>

<span id="busuanzi_container_site_pv">
    <span id="busuanzi_value_site_pv"></span>
</span>


        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    
	
    

    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=6.3.0"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=6.3.0"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=6.3.0"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=6.3.0"></script>



  

  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=6.3.0"></script>



  



  










  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("CIBUz5A0KNFv8xbAPO8ncqk6-gzGzoHsz", "YtGifAKqwENTTs9hhQ1GxdAG");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            
            counter.save(null, {
              success: function(counter) {
                
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(counter.get('time'));
                
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            
              var newcounter = new Counter();
              /* Set ACL */
              var acl = new AV.ACL();
              acl.setPublicReadAccess(true);
              acl.setPublicWriteAccess(true);
              newcounter.setACL(acl);
              /* End Set ACL */
              newcounter.set("title", title);
              newcounter.set("url", url);
              newcounter.set("time", 1);
              newcounter.save(null, {
                success: function(newcounter) {
                  var $element = $(document.getElementById(url));
                  $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
                },
                error: function(newcounter, error) {
                  console.log('Failed to create');
                }
              });
            
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  
  

  

  

  

  

  

</body>
</html>
